<template>
  <transition name="rotate-push-left-to-right">
    <div class="pageContainer dialog-timeobj">
      <!--增加、删除、查询、刷新-->
      <div class="handle-box">
        <el-button
          type="primary"
          size="mini"
          :loading="isLoadData"
          icon="el-icon-refresh"
          @click="handleRefresh"
        >{{$t('global.refresh')}}</el-button>
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-plus"
          @click="handleAdd"
        >{{$t('global.add')}}</el-button>
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-delete"
          @click="delAll"
        >{{$t('global.batchDel')}}</el-button>

        <el-input
          v-model="select_word"
          v-bind:placeholder="$t('global.searkKey')"
          class="handle-input mr10"
          clearable
        ></el-input>
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-search"
          class="search"
          @click="search"
        >{{$t('global.search')}}</el-button>
      </div>

      <!--表格-->
      <el-table
        border
        :data="tableData"
        :style="tableStle"
        :max-height="tableStle.height.split('px')[0]"
        :default-sort="{prop: 'name', order: 'ascending'}"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          type="index"
          :index="indexHandle"
          v-bind:label="$t('global.serialNum')"
          prop="serialNum"
          width="65"
        ></el-table-column>
        <el-table-column v-bind:label="$t('global.name')" sortable prop="name" align="center"></el-table-column>
        <el-table-column
          v-bind:label="$t('firewall.timeObject')"
          prop="info"
          align="center"
          width="860"
          :show-overflow-tooltip="true" 
        ></el-table-column>
        <el-table-column
          v-bind:label="$t('global.operation')"
          prop="operation"
          align="center"
          width="130"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >{{$t('global.edit')}}</el-button>
            <el-button
              type="primary"
              size="mini"
              @click="handleDelete(scope.$index, scope.row)"
            >{{$t('global.del')}}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @current-change="handleCurrentChange"
          layout="total,prev,pager,next"
          :page-size="pageSize"
          :total="recordTotal"
        ></el-pagination>
      </div>

      <!--添加、编辑弹框-->
      <el-dialog
        v-bind:title="dialogTitle"
        :visible.sync="showDialog"
        width="50%"
        class="addedit-dialog"
      >
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item
            v-bind:label="$t('global.name')"
            label-width="140px"
            prop="name"
            :rules="rules.checkHanziZimNumRequired"
          >
            <el-input v-model="form.name" clearable v-bind:placeholder="$t('placeholder.timeName')"></el-input>
          </el-form-item>

          <div class="handle-box">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-plus"
              @click="handleInnerAdd"
            >{{$t('firewall.addTimeParagraph')}}</el-button>
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-delete"
              @click="delInnerAll"
            >{{$t('global.batchDel')}}</el-button>
          </div>

          <el-table
            :data="tableDataInner"
            border
            :max-height="251"
            class="table-inner"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column
              type="index"
              :index="indexHandle"
              v-bind:label="$t('global.serialNum')"
              prop="serialNum"
              width="65"
            ></el-table-column>
            <el-table-column v-bind:label="$t('global.cycle')" prop="weekdays" align="center"></el-table-column>
            <el-table-column v-bind:label="$t('global.time')" prop="time" align="center"></el-table-column>
            <el-table-column
              v-bind:label="$t('global.operation')"
              prop="operation"
              align="center"
              width="130"
            >
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  @click="handleInnerEdit(scope.$index, scope.row)"
                >{{$t('global.edit')}}</el-button>
                <el-button
                  type="primary"
                  size="mini"
                  @click="handleInnerDelete(scope.$index, scope.row)"
                >{{$t('global.del')}}</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- <div class="pagination">{{$t('global.totalRecord')}}：{{recordTotal}}</div> -->
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="showDialog = false">{{$t('global.cancel')}}</el-button>
          <el-button
            type="primary"
            :loading="isSaving"
            @click="saveForm('form')"
          >{{$t('global.save')}}</el-button>
        </span>

        <!-- 内弹框 -->
        <el-dialog
          v-bind:title="dialogInnerTitle"
          :visible.sync="innerVisible"
          append-to-body
          width="45%"
          class="dialog-inner"
        >
          <el-form :model="ruleForm" ref="ruleForm" label-width="140px" class="cycle-form">
            <el-form-item v-bind:label="$t('global.cycle')" prop="cycle" :rules="rules.checkbox">
              <el-checkbox-group v-model="ruleForm.cycle">
                <el-checkbox v-bind:label="1" name="monday">{{$t('global.monday')}}</el-checkbox>
                <el-checkbox v-bind:label="2" name="tuesday">{{$t('global.tuesday')}}</el-checkbox>
                <el-checkbox v-bind:label="3" name="wednesday">{{$t('global.wednesday')}}</el-checkbox>
                <el-checkbox v-bind:label="4" name="thursday">{{$t('global.thursday')}}</el-checkbox>
                <el-checkbox v-bind:label="5" name="friday">{{$t('global.friday')}}</el-checkbox>
                <el-checkbox v-bind:label="6" name="saturday">{{$t('global.saturday')}}</el-checkbox>
                <el-checkbox v-bind:label="7" name="sunday">{{$t('global.sunday')}}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>

            <el-form-item v-bind:label="$t('global.time')" prop="timePicker" :rules="rules.timepicker">
              <el-time-picker
                is-range
                v-model="ruleForm.timePicker"
                v-bind:range-separator="$t('global.to')"
                v-bind:start-placeholder="$t('global.selectItem')"
                v-bind:end-placeholder="$t('global.selectItem')"
                :editable="false"
              ></el-time-picker>
            </el-form-item>
          </el-form>

          <span slot="footer" class="dialog-footer">
            <el-button @click="innerVisible = false">{{$t('global.cancel')}}</el-button>
            <el-button
              type="primary"
              :loading="isInnerSaving"
              @click="saveInnerForm('ruleForm')"
            >{{$t('global.save')}}</el-button>
          </span>
        </el-dialog>
      </el-dialog>

      <!--删除内部时间对象弹框-->
      <el-dialog
        v-bind:title="$t('global.tipDialogTitle')"
        :visible.sync="delInnerVisible"
        width="300px"
        center
      >
        <div class="del-dialog-cnt">{{$t('global.isDel')}}</div>

        <span slot="footer" class="dialog-footer">
          <el-button @click="delInnerVisible = false; isInnerSaving = false">{{$t('global.cancel')}}</el-button>
          <el-button
            type="primary"
            :loading="isInnerSaving"
            @click="deleteInnerRow"
          >{{$t('global.del')}}</el-button>
        </span>
      </el-dialog>

      <!--删除弹框-->
      <el-dialog
        v-bind:title="$t('global.tipDialogTitle')"
        :visible.sync="delVisible"
        width="300px"
        center
      >
        <div class="del-dialog-cnt">{{$t('global.isDel')}}</div>

        <span slot="footer" class="dialog-footer">
          <el-button @click="delVisible = false; isSaving = false">{{$t('global.cancel')}}</el-button>
          <el-button type="primary" :loading="isSaving" @click="deleteRow">{{$t('global.del')}}</el-button>
        </span>
      </el-dialog>

      <!--批量删除记录内部时间对象弹出框-->
      <el-dialog
        v-bind:title="$t('global.tipDialogTitle')"
        :visible.sync="delInnerAllVisible"
        width="300px"
        center
      >
        <div class="del-dialog-cnt">{{$t('global.isDelAll')}}</div>
        <span slot="footer" class="dialog-footer">
          <el-button
            @click="delInnerAllVisible = false; isInnerSaving = false"
          >{{$t('global.cancel')}}</el-button>
          <el-button
            type="primary"
            :loading="isInnerSaving"
            @click="deleteInnerAllHandle"
          >{{$t('global.yes')}}</el-button>
        </span>
      </el-dialog>

      <!--批量删除记录弹出框-->
      <el-dialog
        v-bind:title="$t('global.tipDialogTitle')"
        :visible.sync="delAllVisible"
        width="300px"
        center
      >
        <div class="del-dialog-cnt">{{$t('global.isDelAll')}}</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="delAllVisible = false; isSaving = false">{{$t('global.cancel')}}</el-button>
          <el-button
            type="primary"
            :loading="isSaving"
            @click="deleteAllHandle"
          >{{$t('global.yes')}}</el-button>
        </span>
      </el-dialog>
    </div>
  </transition>
</template>

<script>
import rules from "@/util/rules";
import Cookie from "js-cookie";
import Qs from "qs";
import Vue from "vue";

export default {
  data() {
    return {
      rules,

      timePicker: [
        new Date(1970, 1, 1, 0, 0, 0),
        new Date(2999, 12, 31, 23, 59, 59)
      ],

      ruleForm: {
        cycle: [],
        timePicker: [],
      },

      form: {
        name: "",
        timeObject: ""
      },

      tableData: [
        // {id: 1, name: '上班',  timeObject: '星期一、星期二、星期三 09:00-17:00，星期四、星期五 09:00-16:00，星期六、星期日 09:00-12:00',},
        // {id: 2, name: '上班',  timeObject: '星期一、星期二、星期三 09:00-17:00，星期四、星期五 09:00-16:00，星期六、星期日 09:00-12:00',},
        // {id: 3, name: '上班',  timeObject: '星期一、星期二、星期三 09:00-17:00，星期四、星期五 09:00-16:00，星期六、星期日 09:00-12:00',},
      ],

      tableDataInner: [
        // {id: 1, weekdays: '星期一、星期二、星期三',  time: '09:00-17:00'},
        // {id: 2, weekdays: '星期四、星期五',  time: '09:00-17:00'},
        // {id: 3, weekdays: '星期六、星期日',  time: '09:00-17:00'},
      ],

      tableStle: {
        height: "520px"
      },

      isLoadData: false,
      isSaving: false,
      isInnerSaving: false,
      innerVisible: false,

      pageIndex: 1,
      pageSize: 10,
      recordTotal: 3,
      select_word: "",
      is_search: false,
      idx: -1,
      delVisible: false,
      delInnerVisible: false,
      dialogTitle: "",
      dialogInnerTitle: "",
      showDialog: false,
      multipleSelection: [],

      delAllVisible: false,
      delInnerAllVisible: false,
      batchIds: "",
      innerform: {
        id: null,
        weekdays: "",
        time: ""
      }
    };
  },

  created() {
    this.tableStle.height = "560px";
  },

  mounted() {
    //静态数据
    //this.tableData = []
    //return;
    let self = this;
    self.initPageSize();
    self.getData();

    window.onresize = function(e) {
      self.initPageSize();
    };
  },
  methods: {
    //初始化界面大小
    initPageSize() {
      //设置table高度
      let winH = $(window).height();
      this.tableStle.height = winH - 230 + "px";
    },

    //刷新
    handleRefresh() {
      this.pageIndex = 1;
      this.recordTotal = 0;
      this.tableData = [];
      this.getData();
    },

    //搜索
    search() {
      this.tableData = [];
      this.pageIndex = 1;
      this.getData();
    },

    //删除一条记录
    handleDelete(index, row) {
      let self = this;
      self.idx = row.id;
      self.delVisible = true;
      self.isSaving = false;
    },

    //内部时间对象删除
    handleInnerDelete(index, row) {
			//debugger;
      let self = this;
      self.idx = row.id;
      self.delInnerVisible = true;
      self.isInnerSaving = false;
      //this.tableDataInner.splice(this.idx,1);
    },

    //批量删除
    delAll() {
      const length = this.multipleSelection.length;
      if (0 == length) {
        this.$message.error(this.$t("global.selectItemToDel"));
        return;
      }
      let ids = "";
      for (let i = 0; i < length; i++) {
        if (i == 0) {
          ids = this.multipleSelection[0].id;
        } else {
          ids += "," + this.multipleSelection[i].id;
        }
      }
      this.delAllVisible = true;
      this.batchIds = ids;
    },

    //批量删除内部时间对象
    delInnerAll() {
      const length = this.multipleSelection.length;
      if (0 == length) {
        this.$message.error(this.$t("global.selectItemToDel"));
        return;
      }
      let ids = "";
      for (let i = 0; i < length; i++) {
        if (i == 0) {
          ids = this.multipleSelection[0].id;
        } else {
          ids += "," + this.multipleSelection[i].id;
        }
      }
      this.delInnerAllVisible = true;
      this.isInnerSaving = false;
      this.batchIds = ids;
    },

    //确定批量删除
    deleteAllHandle() {
      this.excuteDel(this.batchIds);
    },

    //确定批量删除内部时间对象
    deleteInnerAllHandle() {
      //debugger;
      this.excuteInnerDel(this.batchIds);
    },

    //确定删除
    deleteRow() {
      this.excuteDel(this.idx);
    },

    //确定删除内部时间对象
    deleteInnerRow() {
      this.excuteInnerDel(this.idx);
    },

    //执行内部时间对象删除
    excuteInnerDel(idx) {
      let self = this;
      self.isInnerSaving = true;
      let ids = idx;
      if (ids && ids.toString().indexOf(",") !== -1) {
        ids = ids.split(",");
      }
      ////console.log(ids);
      //console.log(self.tableDataInner);
      if (ids.length > 1) {
        for (var j = 0; j < self.tableDataInner.length; j++) {
          for (var i = 0; i < ids.length; i++) {
            if (self.tableDataInner[j].id == ids[i]) {
              //if(j == ids[i]){
              self.tableDataInner.splice(j, 1);
              if(j > 0){
                 j--;
              }else {
                j = 0;
              }
            }
          }
        }
      } else {
        for (var j = 0; j < self.tableDataInner.length; j++) {
          if (self.tableDataInner[j].id == ids) {
          //if(j == ids){
            self.tableDataInner.splice(j, 1);
          }
        }
      }

      ////console.log(self.tableDataInner);
      self.delInnerAllVisible = false;
      self.delInnerVisible = false;
      self.isInnerSaving = false;
      self.batchIds = "";
    },

    //执行删除
    excuteDel(ids) {
      let self = this;
      self.isSaving = true;
      // let param = {
      //   "method": "delete_packetFilter",
      //   "param": {
      //     "id": ids.toString()
      //   }
      // };

      // this.socketApi.sendSock(param, function (dataObj) {
      //   self.isSaving = false;
      //   self.delVisible = false;
      //   self.getData();

      // self.delAllVisible = false;
      // self.batchIds = "";
      // });

      let param = {
        id: ids,
        "token": this.$store.state.app.token,
      };

      this.$axios
        .post("api/object_time_name_del ", Qs.stringify(param))
        .then(res => {
          self.isSaving = false;
          self.delVisible = false;
          if (res.data.result == 8000) {
							this.$router.push({
								name: 'login',
								params: {
									timeout: 8000,
									desc: res.data.desc,
								}
							});
							return;
						}
          self.getData();
          self.delAllVisible = false;
          self.batchIds = "";
        });
    },

    indexHandle(index) {
      var indexNum = index + 1;
      if (this.pageIndex > 1) {
        indexNum = this.pageIndex * this.pageSize + indexNum - 10;
      }
      return indexNum;
    },
    transInfo(data) {
      let weekdays = [];
      if (data != null && data.indexOf(",") != -1) {
        weekdays = data.split(",");
        let week = "";
        for (var t = 0; t < weekdays.length; t++) {
          if (t == 0) {
            week = this.transWeek(parseInt(weekdays[t]));
          } else {
            week += "、" + this.transWeek(parseInt(weekdays[t]));
          }
        }
        data = week;
      } else {
        data = this.transWeek(parseInt(data));
      }
      return data;
    },

    //查询列表数据
    getData() {
      this.isLoadData = true;
      // let param = {
      //   "method": "get_timeObject",
      //   "param": {
      //     "pageIndex": this.pageIndex,
      //     "pageSize": this.pageSize,
      //     "fuzzy_match": this.select_word
      //   }
      // }
      // this.socketApi.sendSock(param,this.getDataCb);

      var param = {
        pageIndex: this.pageIndex,
        pageSize: this.pageSize,
        fuzzy_match: this.select_word,
        "token": this.$store.state.app.token,
      };

      this.$axios
        .post("api/object_time_name_list ", Qs.stringify(param))
        .then(res => {
          let dataObj = [];
          if (res.hasOwnProperty("data")) {
            dataObj = res.data;
          } 
          this.getDataCb(dataObj);
        });
    },

    //获取数据回调
    getDataCb(dataObj) {
      this.isLoadData = false;
      if (null == dataObj) {
        this.recordTotal = 0;
        this.tableData = [];
        return;
      }
      if (dataObj.result == 8000) {
						this.$router.push({
							name: 'login',
							params: {
								timeout: 8000,
								desc: dataObj.desc,
							}
						});
						return;
					}
      if (dataObj.method != "object_time_name_list") {
        //php接口测试
        //if (dataObj.method != 'get_timeObject') {
        this.recordTotal = 0;
        this.tableData = [];
        return;
      }
      if ("failed" == dataObj.result) {
        this.recordTotal = 0;
        this.tableData = [];
        return;
      }
      this.recordTotal = parseInt(dataObj.recordTotal); //php
      //this.recordTotal = dataObj.recordTotal;

      let tableData = dataObj.data;
      //console.log(tableData);
      //this.tableDataInner = [];
      for (var i = 0; i < tableData.length; i++) {
        let parent_info = [];
        let info = tableData[i].info;
        if(info.length > 0){
           // let inner_data = [];
          for (var j = 0; j < info.length; j++) {
            let child_info = info[j];
            let self = this;
            let time_info = "";
            //let inner_info = Object.create(null);
            //inner_info.id = i;
            //console.log(child_info.weekdays);
            //inner_info.weekdays = self.transInfo(child_info.weekdays);
            //inner_info.time = child_info.time_begin + "-" + child_info.time_end;
            time_info =
              self.transInfo(child_info.weekdays) +
              "  " +
              child_info.time_begin +
              "-" +
              child_info.time_end;
            //inner_data.push(inner_info);
            //console.log("weeks"+self.transInfo(child_info.weekdays));
            parent_info.push(time_info);
        }
        tableData[i].info = parent_info.join();
       // this.tableDataInner[i] = inner_data;
        }
      }
      this.tableData = tableData;
      //console.log(this.tableData);
    },

    //选中记录
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    //分页请求
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getData();
    },

    //添加弹框
    handleAdd() {
      let self = this;
      self.isSaving = false;
      self.showDialog = true;
      self.dialogTitle = self.$t("firewall.addTimeObject");
      setTimeout(function() {
        self.$refs["form"].clearValidate();
      }, 500);
      self.form.name = "";
      //self.form.timeObject = "" ;
      this.tableDataInner = [];
    },

    //编辑弹框
    handleEdit(index, row) {
      let self = this;
      self.isSaving = false;
      self.showDialog = true;
      self.idx = index;
      self.tableDataInner = [];
      const item = row;
      let item_info = item.info;
      if(item_info.indexOf(',') != -1){
        item_info = item_info.split(',');
      }else if(item_info.length != 0){
        item_info = new Array([item_info]);
      }else {
        item_info = [];
      }
      //console.log(item_info);
      let len_info = (item_info != null && item_info != undefined && item_info.hasOwnProperty('length')) ? item_info.length: 0;
      self.dialogTitle = self.$t("firewall.editTimeObject");
      setTimeout(function() {
        self.$refs["form"].clearValidate();
      }, 500);

      self.form = {
        id: item.id,
        name: item.name
        //timeObject: item.timeObject,
			};
      if(len_info > 0){
        for(var i=0 ; i< len_info; i++){
          let inner_obj = Object.create(null);   
          inner_obj.id = i;
          let info = item_info[i].toString();
          //console.log("info:"+info);
          let weeks = info.split("  ");
          inner_obj.weekdays = weeks[0];
          inner_obj.time = weeks[1];
          //inner_obj.id = item.id;
          self.tableDataInner.push(inner_obj);
        }
      }
        //console.log(self.tableDataInner);
    },

    handleInnerAdd(index, row) {
      let self = this;
      self.innerVisible = true;
      self.isInnerSaving = false;
      self.dialogInnerTitle = this.$t("firewall.addTimeParagraph");
       setTimeout(function() {
        self.$refs["ruleForm"].clearValidate();
      }, 500);
      // self.innerform = {
      // 	id: null,
      // 	weekdays: '' ,
      // 	time: ''
      // }
      self.ruleForm = {
        id:null,
        cycle: []
        // timePicker: []
      };
    },

    handleInnerEdit(index, row) {
      let self = this;
      self.isInnerSaving = false;
      self.innerVisible = true;
      self.idx = row.id;
      //console.log("idx:"+self.idx);
      //const item = this.tableDataInner[index];
      //self.ruleForm.id = row.id;
			setTimeout(function() {
        self.$refs["ruleForm"].clearValidate();
      }, 500);
      //console.log(item);
      self.dialogInnerTitle = self.$t("firewall.editTimeParagraph");
      // setTimeout(function () {
      // 	self.$refs['form'].clearValidate();
      // }, 500);
      // self.innerform = {
      // 	//id: item.id,
      // 	cycle: item.weekdays ,
      // 	time: item.time
      // }
      let times = row.time.split("-");
      let weekdays = row.weekdays.split("、");
      for (var i = 0; i < weekdays.length; i++) {
        weekdays[i] = self.transWeekNum(weekdays[i]);
      }
      this.ruleForm.cycle = weekdays;
      let year = new Date().getFullYear();
      let month = new Date().getMonth();
      let day = new Date().getDay();
      let times_hour = times[0].split(":");
      let times_hour1 = times[1].split(":");
      self.ruleForm.timePicker = [new Date(year,month,day,times_hour[0],times_hour[1],times_hour[2]), new Date(year,month,day,times_hour1[0],times_hour1[1],times_hour1[2])];
      //console.log(this.ruleForm);
    },

    //保存
    saveForm(formName) {
      let self = this;
      this.$refs[formName].validate(valid => {
        if (!valid) {
          return;
        }

        let saveData = {};
        let msg = "";
        var param = {};
        param.name = self.form.name;
        //console.log(self.tableDataInner);
        let formInfoData = [];
        formInfoData = JSON.parse(JSON.stringify(self.tableDataInner));
        //console.log(formInfoData);
        for (var i = 0; i < formInfoData.length; i++) {
          let times = "";
          if (self.tableDataInner[i].time == "") {
            formInfoData[i].time_begin = "";
            formInfoData[i].time_end = "";
          } else {
            times = self.tableDataInner[i].time.split("-");
            formInfoData[i].time_begin = times[0];
            formInfoData[i].time_end = times[1];
          }

          let weekdays = formInfoData[i].weekdays;
          weekdays = weekdays.split("、");
          let week = "";
          for (var s = 0; s < weekdays.length; s++) {
            if (s == 0) {
              week = self.transWeekNum(weekdays[s]);
            } else {
              week += "," + self.transWeekNum(weekdays[s]);
            }
          }
          formInfoData[i].weekdays = week;
          delete formInfoData[i].time;
          delete formInfoData[i].id;
        }
        param.info = JSON.stringify(formInfoData);
				param.token = this.$store.state.app.token;
        if (self.dialogTitle == self.$t("firewall.addTimeObject")) {
          self.isSaving = true;
          msg = self.$t("firewall.addTimeObject");
          param.id = "";
          //saveData.method = "add_timeObject";
          saveData.method = "object_time_name_addedit"; //php
          ////console.log(saveData);
        } else {
          self.isSaving = true;
          msg = self.$t("firewall.editTimeObject");
          param.id = self.form.id;
          //console.log("id:"+param.id);
          //saveData.method = "modify_timeObject";
          saveData.method = "object_time_name_addedit"; //php
          ////console.log(saveData);
        }
        // self.socketApi.sendSock(saveData, (resultObj) => {
        // 	if ("success" == resultObj.result) {
        // 		self.$message.success(this.$t('global.saveSuccess'));
        // 		self.getData();
        // 	} else {
        // 		self.$message.error(this.$t('global.saveFail') + ':' + resultObj.desc);
        // 	}
        // 	self.isSaving = false;
        // 	self.showDialog = false;
        // });
        //console.log(JSON.stringify(param));
				saveData.param = param;
				//console.log(param);
				//console.log(self.tableDataInner);
        this.$axios
          .post("api/" + saveData.method, Qs.stringify(saveData.param))
          .then(res => {
            if (res.data.result == 8000) {
							this.$router.push({
								name: 'login',
								params: {
									timeout: 8000,
									desc: res.data.desc,
								}
							});
							return;
						}
            //php
            if ("success" == res.data.result) {
              self.$message.success(this.$t("global.saveSuccess"));
              self.getData();
            } else {
              self.$message.error(
                this.$t("global.saveFail") + ":" + res.data.desc
              );
            }
            self.isSaving = false;
            self.showDialog = false;
          });
      });
    },
    transWeek(week) {
      switch (week) {
        case 1:
          week = this.$t("global.monday");
          break;
        case 2:
          week = this.$t("global.tuesday");
          break;
        case 3:
          week = this.$t("global.wednesday");
          break;
        case 4:
          week = this.$t("global.thursday");
          break;
        case 5:
          week = this.$t("global.friday");
          break;
        case 6:
          week = this.$t("global.saturday");
          break;
        case 7:
          week = this.$t("global.sunday");
          break;
      }
      return week;
    },
    transWeekNum(week) {
      switch (week) {
        case "星期一":
          week = 1;
          break;
        case "星期二":
          week = 2;
          break;
        case "星期三":
          week = 3;
          break;
        case "星期四":
          week = 4;
          break;
        case "星期五":
          week = 5;
          break;
        case "星期六":
          week = 6;
          break;
        case "星期日":
          week = 7;
          break;
      }
      return week;
    },

    saveInnerForm(formName) {
      //debugger;
      let self = this;
			self.isInnerSaving = false;
			this.$refs[formName].validate((valid) => {
			if (!valid) {
				return ; 
			}
			 let msg = "";
      if (self.dialogInnerTitle == this.$t("firewall.addTimeObject")) {
        self.isInnerSaving = true;
        msg = this.$t("firewall.addTimeObject");
        let object = Object.create(null);
        object.id = self.tableDataInner.length;    
        let date1, time_begin, date2, time_end;
        if (this.ruleForm.timePicker != null) {
          date1 = new Date(this.ruleForm.timePicker[0]);
          time_begin =
            (date1.getHours() >= 10
              ? date1.getHours()
              : "0" + date1.getHours()) +
            ":" +
            (date1.getMinutes() >= 10
              ? date1.getMinutes()
              : "0" + date1.getMinutes()) +
            ":" +
            (date1.getSeconds() >= 10
              ? date1.getSeconds()
              : "0" + date1.getSeconds());
          //let time_begin = (date1.getHours() >= 10?date1.getHours():'0'+date1.getHours() )+':'+(date1.getMinutes() >= 10?date1.getMinutes():'0'+date1.getMinutes());
          date2 = new Date(this.ruleForm.timePicker[1]);
          time_end =
            (date2.getHours() >= 10
              ? date2.getHours()
              : "0" + date2.getHours()) +
            ":" +
            (date2.getMinutes() >= 10
              ? date2.getMinutes()
              : "0" + date2.getMinutes()) +
            ":" +
            (date2.getSeconds() >= 10
              ? date2.getSeconds()
              : "0" + date2.getSeconds());
          //let time_end = (date2.getHours() >= 10?date2.getHours():'0'+date2.getHours() )+':'+(date2.getMinutes() >= 10?date2.getMinutes():'0'+date2.getMinutes());
          object.time = time_begin + "-" + time_end;
        } else {
          object.time = "";
        }
        let weekdays = this.ruleForm.cycle;
        //console.log(weekdays);
        let weekday = "";
        for (let index in weekdays) {
          if (index == 0) {
            weekday = self.transWeek(weekdays[index]);
          } else {
            weekday += "、" + self.transWeek(weekdays[index]);
          }
        }
        object.weekdays = weekday;
        self.innerVisible = false;
        if (!self.tableDataInner) {
          self.tableDataInner = [];
        }
        self.tableDataInner.push(object);
      } else {
        self.isInnerSaving = true;
        msg = this.$t("firewall.editTimeObject");
        let newObject = {};
        newObject.id = self.idx;;    
        let date1 = new Date(this.ruleForm.timePicker[0]);
        let time_begin = (date1.getHours() >= 10?date1.getHours():'0'+date1.getHours() )+':'+(date1.getMinutes() >= 10?date1.getMinutes():'0'+date1.getMinutes())+':'+(date1.getSeconds() >= 10?date1.getSeconds():'0'+date1.getSeconds());
        //let time_begin =
          (date1.getHours() >= 10 ? date1.getHours() : "0" + date1.getHours()) +
          ":" +
          (date1.getMinutes() >= 10
            ? date1.getMinutes()
            : "0" + date1.getMinutes());
        let date2 = new Date(this.ruleForm.timePicker[1]);
        let time_end = (date2.getHours() >= 10?date2.getHours():'0'+date2.getHours() )+':'+(date2.getMinutes() >= 10?date2.getMinutes():'0'+date2.getMinutes())+':'+(date2.getSeconds() >= 10?date2.getSeconds():'0'+date2.getSeconds());
        //let time_end =
          (date2.getHours() >= 10 ? date2.getHours() : "0" + date2.getHours()) +
          ":" +
          (date2.getMinutes() >= 10
            ? date2.getMinutes()
            : "0" + date2.getMinutes());
        let weekdays = this.ruleForm.cycle;
        //console.log(weekdays);
        let weekday = "";
        for (let index in weekdays) {
          if (index == 0) {
            weekday = self.transWeek(weekdays[index]);
          } else {
            weekday += "、" + self.transWeek(weekdays[index]);
          }
        }
        newObject.weekdays = weekday;
        newObject.time = time_begin + "-" + time_end;
        self.innerVisible = false;
        self.tableDataInner.splice(self.idx, 1, newObject);
        //Vue.set(this.tableDataInner[index],index,object);
        //console.log(this.tableDataInner);
			}	
		
		 });	
		}	
		},
}
</script>

<style>
.dialog-timeobj .addedit-dialog .el-dialog {
  min-width: 720px;
  margin-top: 19vh !important;
}

.table-inner {
  width: 100%;
  background: #06343a;
}

.dialog-inner {
  margin-top: 11vh !important;
}

.dialog-inner .el-dialog {
  min-width: 650px;
}

.dialog-inner .el-checkbox + .el-checkbox,
.dialog-inner .el-checkbox {
  margin-right: 30px !important;
  margin-left: 0 !important;
}

.dialog-timeobj .el-dialog__footer,
.dialog-inner .el-dialog__footer {
  padding-right: 20px !important;
}

.dialog-timeobj .el-dialog__footer .el-button,
.dialog-inner .el-dialog__footer .el-button {
  padding: 6px 15px;
}

.el-tooltip__popper {
	color: #fff;
}
</style>